class Student{
    private String name;
    public int age;
    public int id;//学号
    /**
     * 1.不要在静态方法里面使用this
     * 2.不能在静态方法里面直接调用静态方法
     * @return
     */
    public static String getSchool() {
        //return this.school;
        //this.name = "xiaoming";
        return school;
    }

    public static void setSchool(String school) {
        Student.school = school;
    }

    private static String school;//学校，不属于对象  属于类  静态的成员变量

    public Student(){
        System.out.println("不带参数的构造方法!");
    }

    {
        //this.name = "实例代码块!";
        //school = "hafu";
        System.out.println("实例代码块 -》 定义在类的内部，和构造方法等方法同级，主要初始化实例的");
    }

    static {
        //this.name = "实例代码块!";
        school = "hafu";
        System.out.println("静态代码块 -》 定义在类的内部，和构造方法等方法同级，主要初始化静态的成员");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Student(String name, int age, int id){
        this.name = name;
        this.age = age;
        this.id = id;
        System.out.println("带有3个参数的构造方法!");
    }

    public void eat(){
        System.out.println(this.name + "吃饭!");
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
    }

    public void print() {
        System.out.println("姓名: " + name + " 年龄: " + age + " ID: " + id);

    }
}
public class TestDemo {

    public static void main(String[] args) {
        Student student1 = new Student("bit",12,1);
        System.out.println(student1);
        //student1.print();
    }
    public static void main3(String[] args) {
        System.out.println(Student.getSchool());
    }

    public static void main2(String[] args) {
        Student student1 = new Student();
        System.out.println("==============");
        Student student2 = new Student();

    }
    public void function(){

    }
    public static void main1(String[] args) {
        Student student1 = new Student();
        Student student4 = new Student();
        Student student3 = new Student();
        //System.out.println(student1.school);//不合理 不合法 不建议这样做
        //System.out.println(Student.school);//合理的 建议这样访问静态的成员
        student1.setName("xiaoming");
        student1.eat();
        Student student2 = new Student("bit",12,1);
    }


}
